package com.znyj.cloud.device.executor;

import com.znyj.cloud.device.async.TaskAsync;
import com.znyj.cloud.device.constant.SysConstant;
import com.znyj.cloud.device.pack.TaskReceivePackage;
import com.znyj.cloud.device.pack.TaskSendPackage;
import org.apache.log4j.Logger;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * Created by gaoliwei02 on 17/5/31.
 */
@Component
public class TaskExecutorService {
    private static final Logger logger = Logger.getLogger(TaskExecutorService.class);

    @Resource
    private ThreadPoolTaskExecutor taskExecutor;

    public void executeUpdateTask(TaskReceivePackage taskReceivePackage) {
        switch (taskReceivePackage.getReturnMsg()) {
            case SysConstant.RETURN_MSG_VALUE.GET_CTRL: {
                taskExecutor.execute(new TaskAsync(taskReceivePackage.getOrderId(), SysConstant.TASK_RECEIVE_OK, SysConstant.CDB_OP.UPDATE_SEND_STATUS));
            }
            break;

            case SysConstant.RETURN_MSG_VALUE.GET_ERROR: {
                taskExecutor.execute(new TaskAsync(taskReceivePackage.getOrderId(), SysConstant.TASK_RECEIVE_ERR, SysConstant.CDB_OP.UPDATE_SEND_STATUS));
            }
            break;
        }
    }

    public void executeInsertTask(TaskSendPackage taskSendPackage) {
        taskExecutor.execute(new TaskAsync(taskSendPackage.getTaskEntity(), SysConstant.CDB_OP.INSERT_TASK));
    }
}
